const path = require('path');
// 插件都是类
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const notifier = require('node-notifier');
const icon = path.join(__dirname,'icon.jpg');
const  SpeedMeasureWebpack5Plugin = require('speed-measure-webpack5-plugin');//打包速度监控工具
const smw = new SpeedMeasureWebpack5Plugin();
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');//打包体积分析监控工具，插件

module.exports=smw.wrap({
    mode:'development',
    devtool:'source-map',//调试工具的选择
    context:process.cwd(),//上下文件目录，根目录
    entry:'./src/index.js',


    output:{
        path:path.resolve(__dirname,'dist'),//输出的路径
        filename:'[name].js'//输出的文件名
    },
    plugins:[
        // 插件友好提示
        new FriendlyErrorsWebpackPlugin({
            onErrors:(serverity,errors)=>{
                let error=errors[0]
                notifier.notify({
                    title:'webpack编译失败了哈',
                    message:serverity+":"+error.name,
                    subtitle:error.file||'',
                    icon
                })
            }
        }),
        // 打包体积分析
        new BundleAnalyzerPlugin({
            analyzerMode:'disabled',//暂时不启动打包报告http服务器
            generateStatsFile:true,//生成state.json报告文件，在dist打包文件中，然后通过命令运行
        })
    ]
    
}
)
